{% macro loadMore(pageIndex,pageSize,count,isCanReply,api) %}

<button class="btn btn-primary btn-load-more">加载更多..</button>


<script>
    const pageIndex = parseInt('{{pageIndex}}'); // 页面加载时获取当前页面
    const pageSize = parseInt('{{pageSize}}'); // 页面加载时获取每页显示博客的数量
    const count = parseInt('{{count}}'); // 博客总量
    let nextPageIndex = pageIndex;
    if (pageSize * pageIndex >= count) {
        $(".btn-load-more").hide();
    }
    // 点击事件
    $(".btn-load-more").click(function() {
        // /api/profile/loadMore/zahngsan/2
        ajax.get('{{api}}' + nextPageIndex, function(err, res) {
            if (err) {
                alert(err)
            }
            // console.log(res)
            nextPageIndex = res.pageIndex;
            res.blogList.forEach(item => {
                    console.log(item.user.avatar)
                    let $image = "";
                    if (item.images) {
                        $image = `<a href="${item.images}" target="_blank">
                        <img src="${item.images}" alt="" width="150" class="blog-images">
                      </a>`
                    }
                    const $loadMoreTemplate = `
                <div class="blog-item">
                  <div class="user-info">
                    <img src="${item.user.avatar}" alt="" class="user-avatar" width="60" height="60" style="border-radius:50%;">
                  </div>
                  <div class="blog-info">
                    <div class="blog-content">
                      <div>
                        <a href="###" class="username">${item.user.nickName}</a>
                        <span class="text">${item.content}</span>
                      </div>
                      ${$image}
                    </div>
                    <div class="create-time">
                      <span>${item.createdAtFormat}</span>

                      {% if isCanReply %}
            <a href="#" class="reply" data-nick-name="${item.user.nickName}" data-user-name="${item.user.userName}" data-content="${item.formatContent}">
                <svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-reply-fill" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
          <path
            d="M9.079 11.9l4.568-3.281a.719.719 0 0 0 0-1.238L9.079 4.1A.716.716 0 0 0 8 4.719V6c-1.5 0-6 0-7 8 2.5-4.5 7-4 7-4v1.281c0 .56.606.898 1.079.62z" />
        </svg>回复
            </a>
            {% endif %}
                    </div>
                  </div>
                </div>
              `
                    $('.item-wrapper').append($loadMoreTemplate)
                })
                // 如果显示的数量=博客总量  隐藏按钮
            if (pageSize * (res.pageIndex) >= count) {
                $(".btn-load-more").hide();
            }
        })
    })
</script>
{% endmacro %}